var n, i = getApp().util;
var util = getApp().util;
var setmaiOut;  //定时器 paimai列表接口
var maiList = getApp().http.anchor_mailistPost; //接口 排麦列表

Page({
    data: {
        // 是否是主持人
        isHost: false,
    },
    onLoad: function(n) {      
    },
    onReady: function() {},
    onShow: function() {
        //档期结束则跳到首页
        var starttime = wx.getStorageSync('dangqiInfo').riqi + " " + wx.getStorageSync('dangqiInfo').starttime
        if ((new Date().getTime() > util.riqiTime(starttime)) || !wx.getStorageSync('dangqiInfo')) {
          if(!dangqiInfo){
            wx.switchTab({
              url: "/page/tabBar/wheat/index"
            })
            return;
          }
        }
        this.getmaiList(true);
        var e = this, t = wx.getStorageSync("dangqiInfo"), a = t.starttime + " — " + t.endtime;
        var userInfo = wx.getStorageSync('userinfo')
        e.setData({
            manager: t.manager,
            id: t.id,
            paimaitime: t.paimaitime,
            beteenTime: a,
            roles: userInfo.roles,
            dangqiInfo:wx.getStorageSync("dangqiInfo")
        }), wx.setNavigationBarTitle({
            title: a
        })
        var o = t.riqi + " " + t.paimaitime;
        n = setInterval(function() {
            new Date().getTime() > i.riqiTime(o) && wx.redirectTo({
                url: "../anchor_paimaizhong/anchor_paimaizhong"
            });
        }.bind(this), "1000");
         

      //paimai列表  每秒调一次
      setmaiOut = setInterval(function () {
        this.getmaiList();
      }.bind(this), "2000")
          
    },
    onHide: function() {
        clearInterval(n);
        clearInterval(setmaiOut);
    },
    onUnload: function() {
        clearInterval(setmaiOut);
        clearInterval(n);
    },
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {
        return i.shareSet(this,"未排");
    },
    updatemainUrl: function() {
        let dangqiInfo = wx.getStorageSync("userinfo")
      if (dangqiInfo.roles.indexOf("1")>-1) {
        wx.navigateTo({
          url: "../xcx_chair/xcx_chair"
        });
       }else{
        wx.navigateTo({
          url: "../xcx_chairChange/xcx_chairChange"
        });
       }
        
    },
  //获取排麦列表
  getmaiList: function (flag = false) {

    var dangqiInfo = wx.getStorageSync('dangqiInfo')
    var token = wx.getStorageSync('userinfo').token
    var hall_id = wx.getStorageSync('hall_info').id
    maiList({
      token,
      dangqiid: dangqiInfo.id,
      hall_id
    }, flag).then(re => {
      //console.log(re, "re.data");
      if (re.code == 0) {


        var my_uid = wx.getStorageSync('userinfo').uid

        let isHost = 0
        if (my_uid == re.zhuchi_info.manager_id) {
          isHost = 1
        }

        this.setData({
          isHost,
          zhuchi_info: re.zhuchi_info
        })

      } else {
        console.log("接口返回数据失败排麦中", re);
      }
    })
  },
});